home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / ipdump.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  2KB  |  86 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "timer.h"
  6. #include "iface.h"
  7. #include "ip.h"
  8. #include "trace.h"
  9. #include "netuser.h"
  10.  
  11. extern FILE *trfp;
  12.  
  13. int
  14. ip_dump(bpp,check)
  15. struct mbuf **bpp;
  16. int check;
  17. {
  18.     void tcp_dump(),udp_dump(),icmp_dump();
  19.     struct ip ip;
  20.     int16 ip_len;
  21.     int16 offset;
  22.     int16 length;
  23.     int16 csum;
  24.  
  25.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  26.         return;    
  27.  
  28.     fprintf(trfp,"IP:");
  29.     /* Sneak peek at IP header and find length */
  30.     ip_len = ((*bpp)->data[0] & 0xf) << 2;
  31.     if(ip_len < IPLEN){
  32.         fprintf(trfp," bad header\n");
  33.         return;
  34.     }
  35.     if(check)
  36.         csum = cksum(NULLHEADER,*bpp,ip_len);
  37.     else
  38.         csum = 0;
  39.  
  40.     ntohip(&ip,bpp);    /* Can't fail, we've already checked ihl */
  41.  
  42.     /* Trim data segment if necessary. */
  43.     length = ip.length - ip_len;    /* Length of data portion */
  44.     trim_mbuf(bpp,length);    
  45.     fprintf(trfp," len %u",ip.length);
  46.     fprintf(trfp," %s",inet_ntoa(ip.source));
  47.     fprintf(trfp,"->%s ihl %u ttl %u",
  48.         inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
  49.     if(ip.tos != 0)
  50.         fprintf(trfp," tos %u",uchar(ip.tos));
  51.     offset = (ip.fl_offs & F_OFFSET) << 3;
  52.     if(offset != 0 || (ip.fl_offs & MF))
  53.         fprintf(trfp," id %u offs %u",ip.id,offset);
  54.     if(ip.fl_offs & DF)
  55.         fprintf(trfp," DF");
  56.     if(ip.fl_offs & MF){
  57.         fprintf(trfp," MF");
  58.         check = 0;    /* Bypass host-level checksum verify */
  59.     }
  60.     if(csum != 0)
  61.         fprintf(trfp," CHECKSUM ERROR (%u)",csum);
  62.  
  63.     if(offset != 0){
  64.         fprintf(trfp,"\n");
  65.         return;
  66.     }
  67.     switch(uchar(ip.protocol)){
  68.     case TCP_PTCL:
  69.         fprintf(trfp," prot TCP\n");
  70.         tcp_dump(bpp,ip.source,ip.dest,check);
  71.         break;
  72.     case UDP_PTCL:
  73.         fprintf(trfp," prot UDP\n");
  74.         udp_dump(bpp,ip.source,ip.dest,check);
  75.         break;
  76.     case ICMP_PTCL:
  77.         fprintf(trfp," prot ICMP\n");
  78.         icmp_dump(bpp,ip.source,ip.dest,check);
  79.         break;
  80.     default:
  81.         fprintf(trfp," prot %u\n",uchar(ip.protocol));
  82.         break;
  83.     }
  84. }
  85.  
  86.